package com.neu.credit.creditscore.common.utils;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Schema(description = "统一返回结果")
@Data
public class Result<T> {

    @Schema(description = "状态码")
    private Integer code;

    @Schema(description = "提示信息")
    private String msg;

    @Schema(description = "返回数据")
    private T data;

    @Schema(description = "动态数据")
    private Map<String, Object> map;

    public Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.map = new HashMap<>();
    }

    public static <T> Result<T> success() {
        return new Result<>(200, "success", null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(200, "success", data);
    }
    public static <T> Result<T> success(String msg, T data) {
        Result<T> result = new Result<>(200,msg,data);
        result.setCode(200);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
    public static <T> Result<T> error(String msg) {
        return new Result<>(500, msg, null);
    }

    public Result<T> add(String key, Object value) {
        this.map.put(key, value);
        return this;
    }
}
